package com.lyt.springboot.util.algorithm;

import java.util.Scanner;

public class S41 {
    public static void main(String[] args) {
        Scanner in  = new Scanner(System.in);
        String s = in.nextLine();
        String l = in.nextLine();

        int i = 0;
        int j = 0;
        while(i<s.length() && j<l.length()) {
            if(s.charAt(i) == l.charAt(j)) {
                i++;
            }
            j++;
        }
        if(i==s.length()) {
            System.out.println(j-1);
        }else {
            System.out.println("-1");
        }
    }

}
